//
//  PTStuLifeServiceListCell.m
//  PlanTech
//
//  Created by ruifeng song on 2018/7/10.
//  Copyright © 2018年  androidlongs. All rights reserved.
//

#import "PTStuLifeServiceListCell.h"
#import "SINACalendarUtils.h"

@interface PTStuLifeServiceListCell()

@property(nonatomic,strong)UIImageView * headerImageView;
@property(nonatomic,strong)UILabel * nameLabel;
@property(nonatomic,strong)UIImageView * genderImageView;
@property(nonatomic,strong)UILabel * receiveGoodsLabel;
@property(nonatomic,strong)UILabel * feeLabel;
//@property(nonatomic,strong)UILabel * releaseLabel;
@property(nonatomic,strong)UILabel * serviceContentLabel;
@property(nonatomic,strong)UILabel * userAddressLabel;

@end

@implementation PTStuLifeServiceListCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.backgroundColor = [UIColor clearColor];
        
        UIView * backView = [[UIView alloc]init];
        backView.layer.cornerRadius = 10.0;
        backView.alpha = 1;
        backView.layer.backgroundColor = [[UIColor colorWithRed:250.0f/255.0f green:250.0f/255.0f blue:250.0f/255.0f alpha:1.0f] CGColor];
        [self.contentView addSubview:backView];
    
        [backView mas_makeConstraints:^(MASConstraintMaker *make) {
           
            make.left.equalTo(self.contentView).with.offset(12);
            make.right.equalTo(self.contentView).with.offset(-12);
            make.top.equalTo(self.contentView).with.offset(0);
            make.bottom.equalTo(self.contentView).with.offset(-10);
        }];
        
        //Shadow 0 for 圆角矩形 2
        CALayer *shadowLayer0 = [[CALayer alloc] init];
        shadowLayer0.frame = backView.bounds;
        shadowLayer0.shadowColor = [UIColor colorWithRed:56.0f/255.0f green:56.0f/255.0f blue:56.0f/255.0f alpha:0.2f].CGColor;
        shadowLayer0.shadowOpacity = 1;
        shadowLayer0.shadowOffset = CGSizeMake(0, 3);
        shadowLayer0.shadowRadius = 6.8;
        CGFloat shadowSize0 = -0.1;
        CGRect shadowSpreadRect0 = CGRectMake(-shadowSize0, -shadowSize0, backView.bounds.size.width+shadowSize0*2, backView.bounds.size.height+shadowSize0*2);
        CGFloat shadowSpreadRadius0 =  backView.layer.cornerRadius == 0 ? 0 : backView.layer.cornerRadius+shadowSize0;
        UIBezierPath *shadowPath0 = [UIBezierPath bezierPathWithRoundedRect:shadowSpreadRect0 cornerRadius:shadowSpreadRadius0];
        shadowLayer0.shadowPath = shadowPath0.CGPath;
        [backView.layer addSublayer:shadowLayer0];
        
        _headerImageView =[[UIImageView alloc]initWithFrame:CGRectMake(12, 29, 62, 62)];
        _headerImageView.layer.cornerRadius = 31;
        _headerImageView.layer.masksToBounds = YES;
        _headerImageView.backgroundColor = [UIColor redColor];
        [backView addSubview:_headerImageView];
        
        CGFloat contentWidth = ScreenWidth - 24 - 83 - 15;
        
        _nameLabel= [[UILabel alloc]initWithFrame:CGRectMake(83,15, contentWidth, 14)];
//        _nameLabel.text = @"宋佳瑛";
        _nameLabel.textColor = PTColor_2e2e2e;
        _nameLabel.font = PTFONT_15;
        [backView addSubview:_nameLabel];
        
        //计算名称宽度

        // 重新设置frame
//        CGFloat sizeWidth = [_nameLabel.text widthForFont:_nameLabel.font];
//        [_nameLabel setFrame:CGRectMake(83, 15, sizeWidth, 14)];
        
        _genderImageView =[[UIImageView alloc]initWithFrame:CGRectMake(_nameLabel.right + 12, 14, 15, 15)];
        [_genderImageView setImage:[UIImage imageNamed:@"gender_woman_img"]];
        [backView addSubview:_genderImageView];
        
        _feeLabel= [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth -85 -12- 15-12,15, 85, 12)];
        //        _feeLabel.text = @"酬金:3RMB";
        _feeLabel.textColor = PTColor_ff3c08;
        _feeLabel.textAlignment = NSTextAlignmentRight;
        _feeLabel.font = PTFONT_BOLD_12;
        [backView addSubview:_feeLabel];
        
//        _releaseLabel= [[UILabel alloc]initWithFrame:CGRectMake(ScreenWidth -35 -12- 15-12,15, 35, 12)];
////        releaseLabel.text = @"10:00";
//        _releaseLabel.textColor = PTColor_2e2e2e;
//        _releaseLabel.textAlignment = NSTextAlignmentRight;
//        _releaseLabel.font = PTFONT_BOLD_12;
//        [backView addSubview:_releaseLabel];
        
        _receiveGoodsLabel= [[UILabel alloc]initWithFrame:CGRectMake(_headerImageView.right + 9, _nameLabel.bottom + 12,contentWidth, 12)];
//        _receiveGoodsLabel.text = @"收货时间：12:00-14:00";
        _receiveGoodsLabel.font = PTFONT_12;
        _receiveGoodsLabel.textColor = PTColor_2e2e2e;
        [backView addSubview:_receiveGoodsLabel];

        _serviceContentLabel= [[UILabel alloc]initWithFrame:CGRectMake(_headerImageView.right + 9, _receiveGoodsLabel.bottom +10, contentWidth, 12)];
//        _serviceContentLabel.text = @"快递点：山西大学东门";
        _serviceContentLabel.font = PTFONT_12;
        _serviceContentLabel.textColor = PTColor_2e2e2e;
        [backView addSubview:_serviceContentLabel];

        _userAddressLabel= [[UILabel alloc]initWithFrame:CGRectMake(_headerImageView.right + 9, _serviceContentLabel.bottom + 10, contentWidth, 12)];
//        _userAddressLabel.text = @"收货地址：山西师范大学女士宿舍多少教室多...";
        _userAddressLabel.font = PTFONT_12;
        _userAddressLabel.textColor = PTColor_2e2e2e;
        [backView addSubview:_userAddressLabel];
    }
    return self;
}

-(void)updateLifeServiceListCellWith:(LifeServiceListModel *)listModel
{
    //头像
    if (listModel.userAvatar && listModel.userAvatar.length > 0) {
        
        [self.headerImageView sd_setImageWithURL:[NSURL URLWithString:listModel.userAvatar] placeholderImage:[UIImage imageNamed:@"list_header_default_img"]];
    }
    //姓名
    self.nameLabel.text = listModel.userName;
    CGFloat sizeWidth = [self.nameLabel.text widthForFont:_nameLabel.font];
    [self.nameLabel setFrame:CGRectMake(83, 15, sizeWidth, 14)];
    
    //性别
    if ([listModel.userGender integerValue] ==1) { //男
        
        [self.genderImageView setImage:[UIImage imageNamed:@"gender_man_img"]];
    }
    else
    {
        [self.genderImageView setImage:[UIImage imageNamed:@"gender_woman_img"]];
    }
    [self.genderImageView setFrame:CGRectMake(self.nameLabel.right + 12, 14, 15, 15)];
    
    //收货时间
    
    NSString *startimeStr=[NSString stringWithFormat:@"%@",listModel.startTime];
    NSString *endTimeStr=[NSString stringWithFormat:@"%@",listModel.endTime];
    
    self.receiveGoodsLabel.text = [NSString stringWithFormat:@"收货时间：%@-%@",[SINACalendarUtils getDateStringWithTimeStr:startimeStr andFormat:@"MM月dd日 HH:mm"],[SINACalendarUtils getDateStringWithTimeStr:endTimeStr andFormat:@"HH:mm"]];
    
   //type;              //类型 （8 快递，9 打印复印，10 捎饭带饭，11 超市代购）
    
    NSString * serviceContentStr = @"";
    NSString * userAddressStr = @"";
    NSString * serviceName = @"";
    NSString * serviceAddress = @"";
    
    switch ([listModel.type integerValue]) {
        case PTLifeService_ExpressType:   //快递
        {
            serviceContentStr = @"快递点：";
            userAddressStr = @"收货地址：";
            serviceName = listModel.destinationAddress;
            serviceAddress = listModel.userAddress;
        }
            break;
        case PTLifeService_PrintType:   //打印复印
        {
            serviceContentStr = @"打印份数：";
            userAddressStr = @"打印地点：";
            if (listModel.copies ==nil) {
                listModel.copies = [NSNumber numberWithInteger:0];
            }
            serviceName = [NSString stringWithFormat:@"%@",listModel.copies];
            serviceAddress = listModel.destinationAddress;
        }
            break;
        case PTLifeService_BuyMealType:   //捎饭带饭
        {
            serviceContentStr = @"餐厅名称：";
            userAddressStr = @"餐厅地址：";
            serviceName = listModel.destinationName;
            serviceAddress = listModel.destinationAddress;
        }
            break;
        case PTLifeService_HotboomType:   //超市代购
        {
            serviceContentStr = @"超市名称：";
            userAddressStr = @"超市地点：";
            serviceName = listModel.destinationName;
            serviceAddress = listModel.destinationAddress;
        }
            break;
    }
    
    //快递点
    self.serviceContentLabel.text = [NSString stringWithFormat:@"%@%@",serviceContentStr,serviceName];
    
    //收货地址
    self.userAddressLabel.text = [NSString stringWithFormat:@"%@%@",userAddressStr,serviceAddress];

    //酬金
    self.feeLabel.text = [NSString stringWithFormat:@"酬金：%@RMB",listModel.reward];
    //发布时间
    
//    NSString *releaseTimeStr=[NSString stringWithFormat:@"%@",listModel.createTime];
    
//    self.releaseLabel.text =[NSString stringWithFormat:@"%@",[SINACalendarUtils getDateStringWithTimeStr:releaseTimeStr andFormat:@"HH:mm"]];
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
